import './jquery/jquery.js';
import PdfAnnotationController from './PdfAnnotationController.js';

var PdfAnnotationBar, PdfAnnotationCommentController;

class AnnotationController {
    static init (previewData)
    {
        // window.unblockWnd = function (wnd)
        // {
        //     $("#viewer").addClass("unblockWnd");
        // };

        // window.reblockWnd = function (wnd)
        // {
        //     $("#viewer").removeClass("unblockWnd");
        // };

        window.PDFViewerApplication.annotationController = new PdfAnnotationController({
            previewData: previewData,
            pdfViewer: window.PDFViewerApplication.pdfViewer,
        });

        // window.PDFViewerApplication.annotationbar = new PdfAnnotationBar({
        //     bar: document.getElementById("annotationbar"),
        //     toggleButton: document.getElementById("viewAnnotation"),
        //     highlightText: document.getElementById("highlightText"),
        //     underlineText: document.getElementById("underlineText"),
        //     strikeoutText: document.getElementById("strikeoutText"),
        //     addText: document.getElementById("addText"),
        //     drawingToolsToggle: document.getElementById("drawingToolsToggle"),
        //     colorSelectionToggle: document.getElementById("colorSelectionToggle"),
        //     drawingToolBar: document.getElementById("drawingToolBar"),
        //     rectangleTool: document.getElementById("rectangleTool"),
        //     ellipseTool: document.getElementById("ellipseTool"),
        //     arrowTool: document.getElementById("arrowTool"),
        //     pencilTool: document.getElementById("pencilTool"),
        //     forkTool: document.getElementById("forkTool"),
        //     colorSelectionBar: document.getElementById("colorSelectionBar"),
        //     blackButton: document.getElementById("blackButton"),
        //     whiteButton: document.getElementById("whiteButton"),
        //     greyButton: document.getElementById("greyButton"),
        //     silverButton: document.getElementById("silverButton"),
        //     darkRedButton: document.getElementById("darkRedButton"),
        //     redButton: document.getElementById("redButton"),
        //     orangeButton: document.getElementById("orangeButton"),
        //     yellowButton: document.getElementById("yellowButton"),
        //     greenButton: document.getElementById("greenButton"),
        //     lightGreenButton: document.getElementById("lightGreenButton"),
        //     darkBlueButton: document.getElementById("darkBlueButton"),
        //     blueButton: document.getElementById("blueButton"),
        //     purpleButton: document.getElementById("purpleButton"),
        //     pinkButton: document.getElementById("pinkButton"),
        //     displayAnnotationToggle: document.getElementById("displayAnnotationToggle"),
        //     annotationController: window.PDFViewerApplication.annotationController
        // });

        // window.PDFViewerApplication.annotationController.setAnnotationBar(window.PDFViewerApplication.annotationbar);


        // window.PDFViewerApplication.annotationCommentController = new PdfAnnotationCommentController({
        //     previewData: previewData,
        //     annotationController: window.PDFViewerApplication.annotationController
        // });
        return this
    }

    static initEvent(previewData)
    {
        window.addEventListener("textlayerrendered", function (e)
        {
            var pageNumber = e.detail.pageNumber;
            var pageIndex = pageNumber - 1;
            var pageView = window.PDFViewerApplication.pdfViewer.getPageView(pageIndex);
            //保证这一页一定有annotationLayer
            if (pageView.annotationLayer.div === null)
            {
                var pageContainer = $("#viewer > div.page[data-page-number='" + pageNumber + "']");
                pageContainer.append("<div class=\"annotationLayer\"></div>");
                pageView.annotationLayer.div = pageContainer.children("div[class=\"annotationLayer\"]")[0];
            }
            if (window.PDFViewerApplication.annotationController && window.PDFViewerApplication.annotationController.displayAnnotation)
            {
                window.PDFViewerApplication.annotationController.loadAnnotation(pageIndex);
            }

            if (window.PDFViewerApplication.annotationController)
            {
                window.PDFViewerApplication.annotationController.fixUnFinishedTextNote(pageIndex);
                window.PDFViewerApplication.annotationController.prepareForHighlight(pageNumber);
                window.PDFViewerApplication.annotationController.prepareForDrawing(pageNumber);
            }
        }, true);

        return this
    }
}

export default AnnotationController;